import java.lang.System;
import java.util.Map;
import java.util.HashMap;

/**
 * 缺失的第⼀个正数
 * 
 * 输⼊：nums = [1,2,0]
 * 输出：3
 */
public class FirstMissingPositive {

    public int solution(int[] nums) {
        if (nums == null) {
            return -1;
        }

        HashMap<Integer, Integer> map = new HashMap();
        for(int i =0; i < nums.length; i++) {
            map.put(nums[i], i);
        }

        for(int i =1; i <= nums.length +1; i++){
            if(!map.containsKey(i)){
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,0};
        System.out.println(new FirstMissingPositive().solution(nums));
    }
}